<template>
    <div id="con">
            <div class="header">
              <div class="sys">
                天津市人民医院查看预约系统
              </div>
              <div class="admin">
                  <div class="adminPict">
                    <img height="30px" width="30px" src="../../assets/admin.png">
                  </div>
                  <div class="adminName">
                    <el-dropdown :hide-on-click="false">
                    <span class="el-dropdown-link">
                       {{uname}} <i class="el-icon-caret-bottom"></i>
                    </span>
                   <el-dropdown-menu slot="dropdown">
                      <el-dropdown-item>
                        <el-button type="text"  @click="dialogFormVisible1 = true">完善信息</el-button>
                      </el-dropdown-item>
                      <el-dropdown-item>
                        <el-button type="text"  @click="dialogFormVisible = true">修改密码</el-button>
                      </el-dropdown-item>
                      <div class="out" @click="loginOut()">               
                         <el-dropdown-item> <router-link to="/Login">退出登录</router-link></el-dropdown-item>
                      </div>
                    </el-dropdown-menu>
                  </el-dropdown>
                  </div>
                  <!-- <div class="adminExit" @click="loginOut()">  -->
              <div class="adminExit"> 
               <el-dialog title="修改密码" :visible.sync="dialogFormVisible">
              <el-form :model="ruleForm" :rules="rules">
               
                 <el-form-item label="原密码" :label-width="formLabelWidth">
                  <el-input v-model="dypwd" autocomplete="off"></el-input>
                </el-form-item>
                     <el-form-item label="密码" prop="pass" :label-width="formLabelWidth">
                         <el-input  v-model="ruleForm.pass" show-password autocomplete="off"></el-input>
                    </el-form-item>
                    <el-form-item label="确认密码" prop="checkPass" :label-width="formLabelWidth">
                          <el-input  v-model="ruleForm.checkPass" show-password autocomplete="off"></el-input>
                    </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary"  @click="updateDoctor()">确 定</el-button>
              </div>
            </el-dialog>
          </div>
            <!-- <div style="width:500px">  -->
           <el-dialog title="完善信息" :visible.sync="dialogFormVisible1">
              <el-form ref="doctor" :model="doctor1" label-width="80px" style="width:600px">
                <el-form-item label="年龄">
                  <el-input  v-model="doctor1.dage"></el-input>
                </el-form-item>
                  <el-form-item label="性别">
                  <el-input  v-model="doctor1.dsex"></el-input>
                </el-form-item>
                   <el-form-item label="身份证号">
                  <el-input v-model="doctor1.didcard"></el-input>
                </el-form-item>
                <el-form-item label="科室">
                  <el-select v-model="doctor1.kkid" style="width:510px">
                    <el-option v-for="ks in kss" :key="ks.kkid" :label="ks.kkname" :value="ks.kkid"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="主治病">
                 <el-select v-model="doctor1.bbid" style="width:510px">
                    <el-option v-for="jibing in jibings" :key="jibing.bid" :label="jibing.jbname" :value="jibing.bid"></el-option>
                  </el-select>
                </el-form-item>
                <!-- <el-form-item label="">
                   <el-cascader
                      v-model="value"
                      :options="options"
                      @change="handleChange">
                    </el-cascader>
                </el-form-item> -->
                  <el-form-item label="地址">
                  <el-input v-model="doctor1.daddress"></el-input>
                </el-form-item>
                 <el-form-item label="头衔">
                  <el-input  v-model="doctor1.dtitle"></el-input>
                </el-form-item>
                <el-form-item>
                  <el-button type="primary" @click="saveDoctor">保存</el-button>
                  <el-button>取消</el-button>
                </el-form-item>
              </el-form>
             
            </el-dialog>
          <!-- </div>  -->
              </div>
              </div>
            <div class="main">
            <el-tabs :tab-position="tabPosition">
              <el-tab-pane label="查看个人信息">
                <div class="doctorManage">
                 <table>
                 <tr>           
                    <td>工号</td>
                    <td>姓名</td>
                    <td>年龄</td>
                    <td>性别</td>
                    <td>电话</td>
                    <td>身份证号</td>
                    <td>籍贯</td>
                    <td>科室</td>
                    <td>主治病</td>
                    <td>职称</td>
                    <!-- <td>操作</td> -->
                   </tr>
                      <tr>
                        <!-- {{doctor}} -->
                          <td>{{doctor.djobnum}}</td>
                          <td>{{doctor.ddname}}</td>
                          <td>{{doctor.dage}}</td>
                          <td>{{doctor.dsex}}</td>
                          <td>{{doctor.dphonenum}}</td>
                          <td>{{doctor.idcard}}</td>
                          <td>{{doctor.daddress}}</td>
                          <td>{{doctor.dkname}}</td>
                          <td>{{doctor.bbname}}</td>
                          <td>{{doctor.dtitle}}</td>
                      </tr>
                    </table>
                </div>
              </el-tab-pane>
              <el-tab-pane label="预约信息管理">
                <div class="orderManage">
                     <table>
                 <tr>                
                    <td style="width:150px">预约编号</td>
                    <td style="width:150px">姓名</td>
                    <td style="width:150px">疾病</td>
                    <td style="width:150px">预约医生</td>
                    <td style="width:150px">医生工号</td>
                    <td style="width:150px">预约时间</td>
                    <td style="width:150px">完成/等待</td>
                 </tr>
                      <tr v-for="order in orders" :key="order.oOid" >
                        <!-- {{order}} -->
                          <td>{{order.ooid}}</td>
                          <td>{{order.uuname}}</td>
                          <td>{{order.bbname}}</td>
                          <td>{{order.ddname}}</td>
                          <td>{{order.djobnum}}</td>
                          <td>{{order.otimes}}</td>
                          <!-- <td>{{order.ostatus}}</td> -->
                          <td>
                              <el-switch
                              v-model="order.ostatus"
                              @change="orderFun(order)"
                              active-color="#13ce66"
                              inactive-color="#ff4949">
                            </el-switch>  
                          </td>
                      </tr>
                    </table>
                </div>
              </el-tab-pane>
              <el-tab-pane label="科室信息管理">
                <div class="ksManage">
                 <table>
                  <tr>                
                    <td style="width:200px">科室id</td>
                    <td style="width:200px">科室名</td>
                     <td style="width:200px">疾病id</td>
                    <td style="width:200px">疾病名</td>
                   </tr>
                  <tr v-for="jibing in jibing2s" :key="jibing.bbid" >
                        <!-- {{jibing}} -->
                          <td>{{jibing.kkid}}</td>
                          <td >{{jibing.kkname}}</td>
                          <td>{{jibing.bbid}}</td>
                          <td>{{jibing.bbname}}</td>
                  </tr>
                  </table>
                    <div class="pagination">
                        <el-pagination
                                background
                                @size-change="handleSizeChange1"
                                @current-change="handleCurrentChange1"
                                :current-page="pageConf1.pageCode"
                                :page-sizes="pageConf1.pageOption"
                                :page-size="pageConf1.pageSize"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="pageConf1.totalPage">
                        </el-pagination>
                    </div>
                </div>
              </el-tab-pane>
             </el-tabs>
            </div>
    </div>
</template>
<script>
import { log } from 'util';
  export default {
     data() {
         var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
        }
      return {
        dypwd:'',
          form: {
          name: '',
          region: '',
          date1: '',
          date2: '',
          delivery: false,
          type: [],
          resource: '',
          desc: '',
        },
          ruleForm: {
          pass: '',
          checkPass: '',
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' },
            { min: 5, message: '长度在不能小于5个字符' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
        },
        pageConf1: {
        //设置一些初始值(会被覆盖)
        pageCode: 0, //当前页
        pageSize: 6, //每页显示的记录数
        totalPage: 12, //总记录数
        pageOption: [4, 10 ,20], //分页选项
      },
        // jibings:[],
       dialogFormVisible1: false,
       dialogFormVisible: false,
        formLabelWidth: '120px',
        value:true,
        doctor1:{
        ddname:'',
        dpassword:'',
        ddid:'',
        djobnum:'',
        dphonenum:'',
        kkid:window.localStorage.getItem('kkid'),
        dage:'',
        dsex:'',
        didcard:'',
        dhead:'',
        daddress:'',
        bbid:window.localStorage.getItem('bbid'),
        dtitle:'',
        dstatus:'',
        didcard:''
        },
        doctor:{},
        // did:window.localStorage.getItem('did'),
        ddid:'',
        orders:[],
        doctors:[],
        kss:[],
        jibings:[],
        jibing2s:[],
        uname:window.localStorage.getItem('dname'),
        jobNum:window.localStorage.getItem('jnum'),
        dpwd:window.localStorage.getItem('dpwd'),
        tabPosition: 'left',
        
      };
    },
    mounted:function(){
       // 关闭浏览器窗口的时候清空浏览器缓存在localStorage的数据
            // window.onbeforeunload = function (e) {
            //     var storage = window.localStorage;
            //     storage.clear()
            // }
      // this.getDoctor();

      this.getKs();
      this.getOne();
      // this.getJiBing2();
      this.getJiBing();
      this.findByPageKs(this.pageConf1.pageCode, this.pageConf1.pageSize);
    
    },
    methods: {
             //pageSize改变时触发的函数
    handleSizeChange1(val) {
       this.pageConf1.pageSize=val
      this.findByPageKs(this.pageConf1.pageCode, val);
      console.log("改变每页显示条数"+val)
    },
    //当前页改变时触发的函数
    handleCurrentChange1(val) {
      console.log("触发改变页数："+val)
      this.findByPageKs(val-1,this.pageConf1.pageSize);
    },
    findByPageKs: function(pageCode,pageSize) {
    
      // console.log("页码" +pageCode);
      // console.log("页数" +pageSize);
      this.$http
        .get("http://"+this.GLOBAL.ipAddress+":8080/jiBing/findByPage", {params:{pageCode:pageCode,pageSize:pageSize}})
        .then(function(data) {
          this.jibing2s = data.body.content;
        });
    },
      orderFun(value){
        console.log("value"+value)
        this.$http.post("http://"+this.GLOBAL.ipAddress+":8080/order/updateOrder",value).then(function(data) {
          // this.getOrder();
        })
      },
      //   onSubmit() {
      //   console.log('submit!');
      // },
      //    getJiBing2(){
      //       //  console.log("jobnum"+this.jobnum)
      //      this.$http.get("http://localhost:8080/jiBing/getAll").then(function(data) {
      //      this.jibing2s = data.body;
      //      console.log(this.jibings);
      //   });
      // },
          getJiBing(){
            //  console.log("jobnum"+this.jobnum)
           this.$http.get("http://"+this.GLOBAL.ipAddress+":8080/jiBing/getJiBing").then(function(data) {
           this.jibings = data.body;
           console.log(this.jibings);
        });
      },
        saveDoctor(){
           this.dialogFormVisible1 = false
           this.doctor1.dpassword=window.localStorage.getItem('dypwd')  
          this.$http.post("http://"+this.GLOBAL.ipAddress+":8080/doctor/saveDoctor",this.doctor1)
           .then(function(data) {
           this.doctor=data.body;
           this.getOne();
      },)
       },
      getOne(){
        console.log("触发getone")
          this.$http.get("http://"+this.GLOBAL.ipAddress+":8080/doctor/getOne?jobNum="+this.jobNum)
           .then(function(data) {
           this.doctor=data.body;
           console.log("doctor:"+data.body)
           this.ddid=this.doctor.ddid
           this.doctor1.ddname=this.doctor.ddname
          this.doctor1.ddid=this.doctor.ddid;
          this.doctor1.dphonenum=this.doctor.dphonenum
          this.doctor1.djobnum=this.doctor.djobnum
          window.localStorage.setItem('dypwd',this.doctor.dpassword)
          this.doctor1.dage=this.doctor.dage
          this.doctor1.dsex=this.doctor.dsex
          this.doctor1.didcard=this.doctor.didcard
          this.doctor1.daddress=this.doctor.daddress
          this.doctor1.dtitle=this.doctor.dtitle
          this.doctor1.dstatus=this.doctor.dstatus
          // this.doctor1.dpassword=this.doctor.dpassword
          this.doctor1.didcard=this.doctor.idcard
          window.localStorage.setItem('kkid',this.doctor1.kkid);
          window.localStorage.setItem('bbid',this.doctor1.bbid);
          //  console.log("this.doctor1"+this.doctor1.ddid)
          //   console.log("this.ddid"+this.ddid)
              this.getOrder();
          
      },)
       },
       updateDoctor(){
         console.log("新密码"+this.newpwd)
         this.doctor1.dpassword=this.ruleForm.pass
            this.dialogFormVisible = false
                console.log("修改未传的doctor"+this.doctor1.dpassword)
                 this.$http.post("http://"+this.GLOBAL.ipAddress+":8080/doctor/JiaMi",this.dypwd)
               .then(function(data){
                 this.dypwd=data.body;
                 console.log("保存的原密码"+window.localStorage.getItem('dypwd'))
                 console.log("加密的原密码："+this.dypwd)
              
            if(window.localStorage.getItem('dypwd')==this.dypwd){         
               this.$http.post("http://"+this.GLOBAL.ipAddress+":8080/doctor/updateDoctor",this.doctor1)
               .then(function(data){
                 this.doctor=data.body;
                 alert("请重新登陆")
                  this.$router.push({path:'/Login'});
                  this.loginOut();
               })
               }else{
                 alert("原密码输入有误")
               }
                })
          },
          getDoctor(){
           this.$http.get("http://"+this.GLOBAL.ipAddress+":8080/doctor/getDoctor").then(function(data) {
           this.doctors = data.body;
           console.log(this.doctors);
        });
      },
          getOrder(){
           console.log("ddid:"+this.ddid)
           this.$http.get("http://"+this.GLOBAL.ipAddress+":8080/order/getMyOrder?ddid="+this.ddid).then(function(data) {
           this.orders = data.body;
           console.log("this orders"+this.orders);
        });
      },
         getKs(){
           this.$http.get("http://"+this.GLOBAL.ipAddress+":8080/ks/getKs").then(function(data) {
           this.kss = data.body;
           console.log(this.kss);
        });
      },
      loginOut(){
        window.localStorage.removeItem('dname')
        window.localStorage.removeItem('kkid')
        window.localStorage.removeItem('bbid')
        window.location.reload
      },
      handleOpen(key, keyPath) {
        console.log(key, keyPath);
      },
      handleClose(key, keyPath) {
        console.log(key, keyPath);
      }
    }
  }
</script>
<style scoped>
.router-link-active {
  text-decoration: none;
}
a{
  text-decoration: none;
}
.title{
 margin-left: 10px;
 font-size: 18px;
 /* background-color: red; */
}
table{
  background-color: white;
  width: 1370px;
  margin-top: 10px;
  margin-left: 8px;
  border-collapse: collapse;
  color:#9e9e9e;
  font-size: 15px;
  font-weight: bold;
}
tr{
  height: 50px;
  border:1px solid #e0e0e0;
}
body{
  margin: 0px;
  padding: 0px;
}
  .header{
    background-color:#0097a7;
    height: 100px;
    font-size: 26px;
    padding-top: 45px;
    padding-left: 35px;
     position: relative;
     color: white;
  }
  .main {
    background-color: #E9EEF3;
    color: #333;
    text-align: center;
    /* line-height: 300px; */
    height: 450px;
    /* font-size: 30px; */
  }
  body > .el-container {
    margin-bottom: 40px;
  }

  .manage{
    /* margin-bottom: 10px; */
    height: 90px;
    width: 200px;
    line-height: 90px;
    /* background-color: brown; */
    font-size: 20px;
    border: 1px grey solid;
  }
   .sys{
    font-weight:800;
    float: left;
    position:absolute;
    left: 40px;
  }
  .admin{
    top: 70px;
     float: left;
     margin-right: 10px;
     position: absolute;
     right: 20px;
     font-size: 18px;
  }
  .adminPict{
    float: left;
    height: 30px;
    width: 50px;
  }
  .adminName{
    float: left;
    margin-right: 16px;
    /* background-color: rebeccapurple; */
  }
  .adminExit{
    padding-top:5px;
    float: left;
    /* background-color: red; */
  }
  .userManage{
    height: 460px;
    width: 1200px;
    line-height: 40px;
  }
  /* a{
    display: none;
  } */

</style>
